#include "Function.h"  
  
void Function::print_sample_pt(double a, double b, int num, string &name){
    double delta = (b-a) / num;
    double x = a;
    ofstream file(name);
    if(file.is_open()){
        for(int i = 0; i <= num; i++){
            file << x << " " << f(x) << endl;
            x += delta;
        }
        file.close();
        cout << "File " << name;
        cout << " created and written successfully.\n";
    }
    else{  
        cout << "Error creating file: " << name << ".\n";  
    }
}

double ProblemA::f(double x) const {  
    return 1.0 / (1.0 + 25.0 * x * x);  
}  
  
double ProblemA::df(double x) const {  
    return -50.0 * x / 
            ((1.0 + 25.0 * x * x) * (1.0 + 25.0 * x * x));  
}  
  
double ProblemA::d2f(double x) const {  
    double a = 5000.0 * x * x - 50.0 * (1.0 + 25.0 * x * x);  
    double b = (1.0 + 25.0 * x * x) * (1.0 + 25.0 * x * x) 
                                    * (1.0 + 25.0 * x * x);  
    return a / b;  
}  
  
double ProblemC::f(double x) const {  
    return 1.0 / (1.0 + x * x);  
}  
  
double ProblemC::df(double x) const {  
    return -2.0 * x / ((1.0 + x * x) * (1.0 + x * x));  
}  
  
double ProblemC::d2f(double x) const {  
    double a = 8.0 * x * x - 2.0 * (1.0 + x * x);  
    double b = (1.0 + x * x) * (1.0 + x * x) * (1.0 + x * x);  
    return a / b;  
}  